package com.xoa.controller.cms;

import com.xoa.service.cms.CmsDocumentPublishService;
import com.xoa.util.common.wrapper.BaseWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@Controller
@RequestMapping("/cmsDocumentPub")
public class CmsDocumentPublishController {
	@Autowired
	private CmsDocumentPublishService docPublishService;
	
	@ResponseBody
	@RequestMapping("/toPub")
	public BaseWrapper toPub(HttpServletRequest request, HttpServletResponse response, String chnlDocIds){
		BaseWrapper baseWrapper=new BaseWrapper();
		try {
			if(chnlDocIds.endsWith(",")){
				chnlDocIds=chnlDocIds.substring(0,chnlDocIds.length()-1);
			}
			String[] docIds =chnlDocIds.split(",");
			for(String id:docIds){
				if(null!=id && !id.equals("")){
					int chnlDocId = Integer.parseInt(id);
					docPublishService.toPub(request,chnlDocId,true);
				}
			}
			baseWrapper.setFlag(true);
			baseWrapper.setStatus(true);
			baseWrapper.setMsg("文章发布成功！");
		} catch (Exception e) {
			baseWrapper.setFlag(true);
			baseWrapper.setStatus(true);
			baseWrapper.setMsg("发布失败！");
			e.printStackTrace();
		}
		return baseWrapper;
	}
}
